/*eslint @typescript-eslint/no-explicit-any: ["error", { "ignoreRestArgs": true }]*/

const defer = <R>(fn: (...params: any[]) => Promise<R>): (...params: any[]) => Promise<R> | undefined => {
  let triggered = false;
  return (...params: any[]) => {
    if (triggered) return;
    triggered = true;
    return fn(...params).then((v) => {
      triggered = false;
      return v;
    });
  };
};

export {
  defer
}